#pragma once
#include "Json/CJsonObject.hpp"
#include "Base64/base_64.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <io.h>
using namespace std;

static int get_files(std::string fileFolderPath, std::string fileExtension, std::vector<std::string>& file)
{
    std::string fileFolder = fileFolderPath + "\\*" + fileExtension;
    std::string fileName;
    struct _finddata_t fileInfo;
    long long findResult = _findfirst(fileFolder.c_str(), &fileInfo);
    if (findResult == -1)
    {
        _findclose(findResult);
        return 0;
    }
    bool flag = 0;

    do
    {
        fileName = fileFolderPath + "\\" + fileInfo.name;
        if (fileInfo.attrib == _A_ARCH)
        {
            file.push_back(fileName);
        }
    } while (_findnext(findResult, &fileInfo) == 0);

    _findclose(findResult);
}

class ObjConversioner
{
private:
    typedef struct point3f
    {
        float x = 0.0;
        float y = 0.0;
        float z = 0.0;
    } point3f;

    typedef struct vertex
    {
        point3f point;
        point3f normal;
    };

    vector<vertex> vertexs;
    vector<unsigned int> faceVertexCounts;
    vector<unsigned int> faceVertexIndices;

    vector<string> split(const string &str, const string &delim);
    void initModel(void);
    string GetBase64ModelMesh(void);

public:
    ObjConversioner(void);
    int LoadObjModel(string _srcFilePath);

    void printModelMesh(void);

    int SaveUsdModel(string _dstFilePath);
    int SaveglTFModel(string _dstFilePath);
};
